package com.example.bbs.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @auther: zhangxin
 * @Description:
 */
public class TimeUtil {
    /**
     * 获取当前时间并转化为Date
     */
    public static Date getCurrentTimeToDate() throws ParseException {
        SimpleDateFormat fmt = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        Date now = new Date();
        String currentTime = fmt.format(now);
        Date date = fmt.parse(currentTime);
        return date;
    }


    public static Date getStringToDate(String time) throws ParseException {
        SimpleDateFormat fmt = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        Date date = fmt.parse(time);
        return date;
    }

    public static String getDateToString(Date time){
        SimpleDateFormat fmt = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        String strTime =  fmt.format(time);
        return strTime;
    }
}
